package rmi.bank;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;

import std.bank.Account;
import std.bank.Bank;

public class BankRMIImpl extends UnicastRemoteObject implements Bank
{
	HashMap<String, Account> accounts;

	protected BankRMIImpl() throws RemoteException
	{
		super();
		accounts = new HashMap<String, Account>();
	}

	public Account getAccount(String name)
	{
		Account account = accounts.get(name);
		if (account != null)
		{
			return account;
		}
		else
		{
			try
			{
				account = new AccountRMIImpl(name, 0);
			}
			catch (RemoteException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			accounts.put(name, account);
			return account;
		}
	}
}
